package com.mzy.linear_struct.hot100.链表;

/**
 * @Author: mizy3
 * @Date: 2024/07/31/下午4:50
 * @Description:
 */
public class Pro141环形链表 {


    public boolean hasCycle(ListNode head) {

        if (head == null) return false;

        ListNode fast = head;
        ListNode slow = head;

        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;

            if (fast == slow) return true;

        }

        return false;
    }


/*    public boolean hasCycle(ListNode head) {
        ListNode s = head;
        ListNode f = head;
        while (f != null && f.next != null) {
            f = f.next.next;
            s = s.next;
            if(s == f) return true;

        }

        return false;
    }*/
}
































